package ch.zbw.pra.sysventory.ui.gui.utilities;

import ch.zbw.pra.sysventory.ui.gui.panels.scanpanel.subpanels.ProgressbarPanel;

public class TimerThread extends Thread {

	private ProgressbarPanel progressBarPanel;

	public TimerThread(ProgressbarPanel progBarP) {
		this.progressBarPanel = progBarP;
	}

	@Override
	public void run() {
		this.progressBarPanel.setVisible(true);
		this.progressBarPanel.setTextRunningOnScanRunLabel();
		int realSendedValueForProgressBar = 0;
		// System.out.println(this.progressBarPanel.getThreadShouldRunState());
		for (int i = 0; i <= 10000; i++) {

			if (this.progressBarPanel.getThreadShouldRunState()) {
				try {
					sleep(10);
				} catch (InterruptedException e) {
				}
				realSendedValueForProgressBar += 1;
				if (realSendedValueForProgressBar <= 100) {
					// System.out.println(realSendedValueForProgressBar);
					this.progressBarPanel.setProgressBarValue(realSendedValueForProgressBar);
				} else {
					realSendedValueForProgressBar = 0;
				}
			}
		}
		this.progressBarPanel.setVisible(false);
		this.progressBarPanel.setTextRunFinishedOnScanRunLabel();
		// this.progressBarPanel.removeProgressbarFromPanel();

	}
}
